/*
** Copyright (C) 2010 Calin Radoni
**
** This file is part of CHScanner.
**
** CHScanner is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** CHScanner is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with CHScanner. If not, see <http://www.gnu.org/licenses/>.
*/

#include "StdAfx.h"
#include "MIGMPPacket.h"

//---------------------------------------------------------------------------

MIGMPPacket::MIGMPPacket(void)
{
	Initialize();
}

MIGMPPacket::~MIGMPPacket(void)
{
}

//---------------------------------------------------------------------------

void MIGMPPacket::Initialize(void)
{
	type = 0;
	addr.Initialize();
	recordType = 0;
}

void MIGMPPacket::LoadFromPointer(MIGMPPacket* dataIn)
{
	if(dataIn==NULL){
		Initialize();
		return;
	}

	type = dataIn->type;
	addr.Set(dataIn->addr.GetD());
	recordType = dataIn->recordType;
}

//---------------------------------------------------------------------------

bool MIGMPPacket::IsEmpty(void)
{
	return type==0 ? true : false;
}

bool MIGMPPacket::IsEqualWith(MIGMPPacket* dataIn)
{
	DWORD a1, a2;
	if(dataIn==NULL) return false;

	if(type!=dataIn->type) return false;

	a1 = addr.GetD();
	a2 = dataIn->addr.GetD();

	if(a1!=a2) return false;

	return recordType!=dataIn->recordType;
}

//---------------------------------------------------------------------------

CString MIGMPPacket::GetTypeName(void)
{
	CString str;

	switch(type){
		case 0x00 :
			str = _T("uninitialized");
			break;

		case 0x11 :
			str = _T("Membership Query");
			break;

		case 0x12 :
			str = _T("Version 1 Membership Report");
			break;

		case 0x16 :
			str = _T("Version 2 Membership Report");
			break;

		case 0x17 :
			str = _T("Version 2 Leave Group");
			break;

		case 0x22 :
			str = _T("Version 3 Membership Report");
			break;

		default :
			str = _T("unknown");
			break;
	}

	return str;
}

CString MIGMPPacket::GetRecordTypeName(void)
{
	CString str;

	switch(recordType){
		case 0 :
			str = _T("uninitialized");
			break;

		case 1 :
			str = _T("Mode is include");
			break;

		case 2 :
			str = _T("Mode is exclude");
			break;

		case 3 :
			str = _T("Change to include mode");
			break;

		case 4 :
			str = _T("Change to exclude mode");
			break;

		case 5 :
			str = _T("Allow New Sources");
			break;

		case 6 :
			str = _T("Block Old Sources");
			break;

		default :
			str = _T("unknown");
			break;
	}

	return str;
}

bool MIGMPPacket::IsReport(void)
{
	if(type==0x12) return true;
	if(type==0x16) return true;
	if(type==0x22) return true;
	return false;
}

//---------------------------------------------------------------------------
